package com.ruoyi.finance.config;

import com.ruoyi.finance.domain.vo.CredentialRollupVo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tjk
 * @Date: 2025/3/3 20:01
 * @Description:
 **/
@Configuration
public class ThreadPoolExecutorConfig {
 @Bean
        public ThreadPoolExecutor threadPoolExecutor() {
         // 设置线程池的核心线程数，这里设置为CPU核心数
         int corePoolSize = Runtime.getRuntime().availableProcessors();
         // 设置线程池的最大线程数，这里设置为核心线程数的两倍
         int maximumPoolSize = corePoolSize * 2;
         // 设置线程池的线程空闲时间，单位为秒
         long keepAliveTime = 60L;
         // 设置线程池的阻塞队列，这里使用LinkedBlockingQueue
         BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(1000);
         // 设置线程池的拒绝策略，这里使用CallerRunsPolicy
         ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                 corePoolSize,
                 maximumPoolSize,
                 keepAliveTime,
                 TimeUnit.SECONDS,
                 workQueue,
                 new ThreadPoolExecutor.CallerRunsPolicy()
         );
         return threadPoolExecutor;
 }

 }

